*1 ) Remove one region at the time

local var daily_increase

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19


levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.1 "-0.10" 0 "0" 0.1 "0.10" 0.2 "0.20" 0.3 "0.30", labsize(large) angle(0)) 

local figure "_`var'_noregion_boundary"


local var tamponi_day

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.3 "-0.30" -0.2 "-0.20" -0.1 "-0.10" 0 "0" 0.1 "0.10", labsize(large) angle(0)) 

local figure "_`var'_noregion_boundary"


local var ratio2

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.2 "-0.20" 0 "0" 0.2 "0.20" 0.4 "0.40" 0.6 "0.60", labsize(large) angle(0))

local figure "_`var'_noregion_boundary"


local var totale_osp

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.2 "-0.20" 0 "0" 0.2 "0.20" 0.4 "0.40" 0.6 "0.60", labsize(large) angle(0)) 

local figure "_`var'_noregion_boundary"


local var terapia

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.05 "-0.05" 0 "0" 0.05 "0.05" 0.1 "0.10" 0.15 "0.15", labsize(large) angle(0)) 

local figure "_`var'_noregion_boundary"


local var deceduti_day

use "../2_Data/temp/data_selected_region.dta", clear

local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend
}




levelsof codice_regione, local(reg)

	matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix REGION = [.]

		
		
foreach regio in `reg' {

eststo clear
    
eststo: qui reg2hdfespatial `var' post_election `trends' if codice_regione!=`regio', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix B = [B,help[1,1]]
matrix CIL = [CIL,help[1,1]-help[1,2]*1.96]
matrix CIU = [CIU,help[1,1]+help[1,2]*1.96]
matrix REGION = [REGION,`regio']

}


		matrix M = [B \ CIL \ CIU \ REGION ]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
		preserve
		collapse (first) codice_regione, by(region)
		
		replace region = "TRENTINO-ALTO ADIGE" if strpos(region,"P.A.")
		rename (codice_regione region) (M4 M4_new)
		duplicates drop
		tempfile m 
		save `m', replace
		restore
		merge m:1 M4 using `m', keep(match master) nogen
		sort M4
		
		
		local varlabels
		forvalues i = 1/20 {
		    local new = M4_new[`i']
		local varlabels `varlabels' `i' "`new'"
		}
		label define yada `varlabels'
		label values M4 yada
		

tw (line M1 M4, lcolor(black) lwidth(medthick)) (line M2 M4, lcolor(gs10)  lpattern(dash)) ///
		       (line M3 M4, lcolor(gs10) lpattern(dash)) (function y = 0 * x, range(M4) lcolor(red)),  scheme(s1mono)  ///
			   graphregion(color(white)) bgcolor(white) ///
			   legend(order(1 2) label(1 "Estimated coefficients") label(2 "95% confidence intervals") cols(1) region(lcolor(white)) just(left) position(7) ring(0) bplacement(sw)) ///  
			   xlabel(1(1)20, labsize(small) valuelabel angle(30)) ylabel(-0.02 "-0.02" 0 "0" 0.02 "0.05" 0.04 "0.04" 0.06 "0.06", labsize(large) angle(0)) 

local figure "_`var'_noregion_boundary"


